package com.ld.admin.util.daliySentence.impl;

import com.alibaba.fastjson.JSONObject;
import com.ld.admin.util.daliySentence.DaliySentence;
import com.ld.admin.util.daliySentence.DaliySentenceUtil;
import com.ld.admin.util.daliySentence.model.DaliySentenceModel;
import com.ld.shieldsb.common.core.util.JsoupUtil;

/**
 * 
 * 一句 每日一句
 * 
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2020年1月8日 上午11:00:51
 *
 */
public class DaliySentenceYiju implements DaliySentence {
    public static final String KEY = "yiju";
    public static final String NAME = "一句";
    public static final String URL = "http://yijuzhan.com/api/word.php?m=json";
    public static final String LINK_URL = "http://yijuzhan.com/";
    public static final String DESCRIPTION = "一句 汇聚有料文字"; // 描述

    @Override
    public DaliySentenceModel getSentence() {
        DaliySentenceModel model = null;
        String htmlContent = null;
        JSONObject jsonObj = JsoupUtil.getRemoteURLJson(getURL());
        /*{"content":"有谁知我此时情，枕前泪共阶前雨，隔个窗儿滴到明。","source":"聂胜琼《鹧鸪天·别情》"}
        content：诗句内容 ｜ source：诗句作者*/
        if (jsonObj != null) {
            model = new DaliySentenceModel();
            String originStr = jsonObj.getString("source");
            String content = jsonObj.getString("content");

            htmlContent = content + "<br/>——" + originStr + DaliySentenceUtil.getLinkedStr(getLinkURL(), NAME);

            model.setHtmlContent(htmlContent);
            model.setContent(content);
            model.setOrigin(originStr);

            model.setBaseInfo(getBaseInfo());
        }
        return model;
    }

    public static void main(String[] args) {
        DaliySentenceYiju test = new DaliySentenceYiju();
        System.out.println(test.getSentence());
    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getURL() {
        return URL;
    }

    @Override
    public String getLinkURL() {
        return LINK_URL;
    }

    @Override
    public String getDescription() {
        return DESCRIPTION;
    }

}
